package cn.hwadee.muying.controller;

import cn.hwadee.muying.commons.constant.ConstantWebContext;
import cn.hwadee.muying.entity.Permission;
import cn.hwadee.muying.entity.User;
import cn.hwadee.muying.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @描述: 后台管理首页控制器
 * @作者: Pengo.Wen
 * @日期: 2017-11-29 16:26
 * @版本: v1.0
 */
@Controller
public class MainController {

    @Autowired
    private HttpSession session;
    @Autowired
    private PermissionService permService;

    @RequestMapping(value = "/console/main", produces = "text/html;charset=utf-8")
    public String main(Model model) throws Exception {
        // TODO 加载用户的菜单
        User user = (User) session.getAttribute(ConstantWebContext.request_cUser);
        List<Permission> menuList = permService.menu(user);
        model.addAttribute("menuList", menuList);
        return "/sys/main";
    }

    @RequestMapping(value = "/index", produces = "text/html;charset=utf-8")
    public String index() throws Exception {
        return "index";
    }

    /*
    @RequestMapping(value = "/test", produces = "text/html;charset=utf-8")
    public String test(Model model) throws Exception {
        SellerService sellerService = SpringContextHolder.getBean(SellerService.class);
        List<Seller> sellers = sellerService.listAllSellers();
        model.addAttribute("sellers", sellers);
        return "test";
    }
    */
}
